// import './js/libs/weapp-adapter'
// import './js/libs/symbol'

// import Main from './js/main'

// new Main()

// const canvas = wx.createCanvas()

const context = canvas.getContext('2d') // 创建一个 2d context

context.fillStyle='red'


const {windowWidth,windowHeight} = wx.getSystemInfoSync();
//封装fillrect
function drawRect(x,y){
  context.clearRect(0,0,windowWidth,windowHeight);
  context.fillRect(x,y,100,100)
}
// drawRect(100,100);

const rectX = 100;
let rectY = 0;
//下落
setInterval(function(){
  drawRect(rectX,rectY++)
},20)

//添加飞机图片
const image = wx.createImage();
const imgX = 100;
let imgY = 400;
image.onload = function(){
  context.drawImage(image,imgX,imgY)
}
image.src = "images/plan100.png";


let touchX = imgX
let touchY = imgY
//图片跟随鼠标东
wx.onTouchMove(function (res) {
  context.clearRect(touchX, touchY, 100, 100); // 清除画布上原有的飞机
  touchX = res.changedTouches[0].clientX // 重新判断当前触摸点x坐标
  touchY = res.changedTouches[0].clientY // 重新判断当前触摸点y坐标
  context.drawImage(image, touchX, touchY);
  if (touchX >= rectX - 100 && touchX <= rectX + 100 && touchY >= rectY - 100 && touchY <= rectY + 100) { // 飞机与矩形发生碰撞
    wx.showModal({
      title: '提示',
      content: '发生碰撞，游戏结束！'
    })
  }
  
})
